//
//  PushNewVideo.m
//  UI_Project_A
//
//  Created by GH on 16/3/6.
//  Copyright © 2016年 GH. All rights reserved.
//

#import "PushNewVideo.h"
#import "HandleData.h"
#import "ModelOfNewPush.h"
#import "NewVideoTableViewCell.h"
#import "SelePushViewController.h"
#import <DKNightVersion.h>

@interface PushNewVideo ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic ,retain)UITableView *tableview;
@property (nonatomic ,retain)NSMutableArray *arrData;

@end

@implementation PushNewVideo

- (void)dealloc {


    [_strTitle release];
    [_arrData release];
    [_tableview release];
    [super dealloc];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self data];
    [self createView];
    [self createTable];
}



- (void) data {

    if (self.arrData == nil) {
        self.arrData = [NSMutableArray array];
    }

 //http://c.3g.163.com/nc/video/list/VAP4BFE3U/n/0-10.html
    NSString *url = [NSString stringWithFormat:@"http://c.3g.163.com/nc/video/list/%@/n/0-50.html",self.sid];
    NSLog(@"%@",url);
    
    [HandleData handleFloewNewWithString:url Block:^(id result) {
    
    NSArray *arrData = [result objectForKey:self.sid];
        
        for (NSDictionary *dic in arrData) {
            
            ModelOfNewPush *newPush = [[ModelOfNewPush alloc] init];

            [newPush setValuesForKeysWithDictionary:dic];
            [self.arrData addObject:newPush];
            [newPush release];
            
            
            
        }
        [self.tableview reloadData];
    }];
    
    

}



- (void)createTable {

    self.tableview = [[UITableView alloc] initWithFrame:CGRectMake(0, 80, WIDTH, HEIGHT) style:UITableViewStylePlain];
    [self.view addSubview:self.tableview];
    self.tableview.dataSource = self;
    self.tableview.delegate = self;
    
    [self.tableview registerClass:[NewVideoTableViewCell class] forCellReuseIdentifier:@"pool"];
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {


    return self.arrData.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NewVideoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"pool"];
    
    ModelOfNewPush *model = [self.arrData objectAtIndex:indexPath.row];
    [cell passModelOfNewPush:model];
    
    cell.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor],[UIColor colorWithWhite:0.247 alpha:1.000]);
    
    

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}



- (void)createView {
    
    UIView *viewOfback = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 80)];
    [self.view addSubview:viewOfback];
    viewOfback.backgroundColor = [UIColor redColor];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(WIDTH/2 - 50, 20, 100, 50)];
    [viewOfback addSubview:label];
    [label release];
    
    label.text = self.strTitle;
    label.font = [UIFont systemFontOfSize:25];
    label.textAlignment = 1;
    label.textColor = [UIColor whiteColor];
    
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [viewOfback addSubview:button];
    [button release];
    button.frame = CGRectMake(20, 20, 50, 50);
    [button setImage:[UIImage imageNamed:@"jiantou3"] forState:UIControlStateNormal];
    
    [button addTarget:self action:@selector(returnButton:) forControlEvents:UIControlEventTouchUpInside];
    
}

- (void)returnButton:(UIButton *)button {
    
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}


- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    return  HEIGHT /7 * 4 - 80;
}



- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    ModelOfNewPush *model = [self.arrData objectAtIndex:indexPath.row];
    SelePushViewController *selePush = [[SelePushViewController alloc] init];
    selePush.model =  model;

    
    
    [self presentViewController:selePush animated:YES completion:nil];
    [selePush release];

}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
